package com.mllweb.blog.service.impl;

import com.mllweb.blog.base.BaseService;
import com.mllweb.blog.data.dao.BlogUserCategoryDao;
import com.mllweb.blog.data.orm.BlogUserCategory;
import com.mllweb.blog.service.CategoryService;
import com.mllweb.blog.web.dto.User;
import com.mllweb.blog.web.session.SessionKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CategoryServiceImpl extends BaseService implements CategoryService {
    @Autowired
    private BlogUserCategoryDao blogUserCategoryDao;

    @Override
    public int insert(BlogUserCategory category) {
        User user = (User) this.getSession().getAttribute(SessionKey.USER.toString());
        category.setUserId(user.getId());
        return blogUserCategoryDao.insert(category);
    }

    @Override
    public List<BlogUserCategory> selectByUserId() {
        User user = (User) this.getSession().getAttribute(SessionKey.USER.toString());
        return blogUserCategoryDao.selectByUserId(user.getId());
    }
}
